package com.yanqu.road.server.cmd.activity.guguoxunbao;

import com.yanqu.road.pb.activity.GuGuoXunBaoProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.guguoxunbao.GuGuoXunBaoModule;
import com.yanqu.road.server.manger.activity.guguoxunbao.GuGuoXunBaoMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_GUGUOXUNBAO_ACTIVITY_EXPLORE, desc = "探索")
public class GuGuoXunBaoExploreCmd extends AbstractCommand {

    int activityId;
    int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GuGuoXunBaoProto.ExploreClueReqMsg reqMsg = GuGuoXunBaoProto.ExploreClueReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        type = reqMsg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(GuGuoXunBaoMgr.getShowTimeActivityId() == 0){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if(!GuGuoXunBaoMgr.activityInTime()){
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        if(type != 1 && type != 2){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }
        ret = player.getModule(GuGuoXunBaoModule.class).explore(type);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            GuGuoXunBaoProto.ExploreClueRespMsg.Builder respMsg = GuGuoXunBaoProto.ExploreClueRespMsg.newBuilder();
            respMsg.setRet(0);
            respMsg.setType(type);
            player.sendPacket(Protocol.U_GUGUOXUNBAO_ACTIVITY_EXPLORE, respMsg);
        }
    }
}
